package com.mxdx.edu.service.impl;

import com.mxdx.edu.dao.ExamLibraryDao;
import com.mxdx.edu.model.ExamStudentRecord;
import com.mxdx.edu.model.StudentScore;
import com.mxdx.edu.service.IExamLibraryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ExamLibraryServiceImpl implements IExamLibraryService {

    @Resource
    private ExamLibraryDao examLibraryDao;

    @Override
    public Map<String, Object> findExamTitleByMap(Map<String, Object> param){

        return examLibraryDao.findExamTitleByMap(param);
    }

    //根据课程id获取考试信息
    @Override
    public Map<String, Object> findExamTitleByCourseId(String courseId){

        Map<String, Object> param = new HashMap<>();
        param.put("courseId", courseId);

        Map<String, Object> examTitleMap = examLibraryDao.findExamTitleByMap(param);

        return examTitleMap;
    }

    //根据考试id获取考试大题信息
    @Override
    public List<Map<String,Object>> findExamSubjectByExamId(String examId){

        Map<String, Object> param = new HashMap<>();
        param.put("examId", examId);

        List<Map<String, Object>>  examSubjectListMap = examLibraryDao.findExamSubjectByMap(param);

        return examSubjectListMap;
    }

    //根据考试id获取考试大题题干信息
    @Override
    public List<Map<String,Object>> findExamMainByExamId(String studentId,String courseId,String semesterId,String examId){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("semesterId",semesterId);
        param.put("examId", examId);

        List<Map<String, Object>>  examMainListMap = examLibraryDao.findExamMainByMap(param);

        return examMainListMap;
    }

    @Override
    public Map<String,Object> findExamMainTestByMap(String testId){

        Map<String, Object> param = new HashMap<>();
        param.put("testId", testId);

        return examLibraryDao.findExamMainTestByMap(param);
    }

    //根据考试id获取考试题干选项信息
    @Override
    public List<Map<String,Object>> findExamOptionByTestId(List<String> testIdList){

        Map<String, Object> param = new HashMap<>();

        param.put("list", testIdList);

        List<Map<String, Object>>  examOptionListMap = examLibraryDao.findExamOptionByMap(param);

        return examOptionListMap;
    }

    //根据考试id获取考试题干答案信息
    @Override
    public List<Map<String,Object>> findExamAnswerByTestId(List<String> testIdList){

        Map<String, Object> param = new HashMap<>();
        param.put("list", testIdList);

        List<Map<String, Object>>  examAnswerListMap = examLibraryDao.findExamAnswerByMap(param);

        return examAnswerListMap;
    }

    //根据考试id获取考试题干详解信息
    @Override
    public List<Map<String,Object>> findExamExplainByTestId(List<String> testIdList){

        Map<String, Object> param = new HashMap<>();
        param.put("list", testIdList);

        List<Map<String, Object>>  examExplainListMap = examLibraryDao.findExamExplainByMap(param);

        return examExplainListMap;
    }

    //学生考试答题列表
    @Override
    public List<ExamStudentRecord> findExamStudentRecordByMap(String studentId,String courseId,String examId){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("examId",examId);

        List<ExamStudentRecord> examStudentRecordList = examLibraryDao.findExamStudentRecordByMap(param);

        return examStudentRecordList;
    }

    //学生考试答题数量
    @Override
    public int findExamStudentCountByMap(String studentId,String courseId,String examId){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("examId",examId);

        int count = examLibraryDao.findExamStudentCountByMap(param);

        return count;
    }

    //学生考试答题题号
    @Override
    public String findExamStudentTestIdsByMap(String studentId,String courseId,String examId){
        String testIds = "";
        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("examId",examId);

        List<Map<String,Object>> testIdList = examLibraryDao.findExamStudentTestIdsByMap(param);
        for(Map<String,Object> testIdMap : testIdList){
            String testid = (String)testIdMap.get("test_id");
            testIds += testid;
        }
        return testIds;
    }

    //学生考试答题题号
    @Override
    public double findNotSubjectiveScore(String examId){
        String testIds = "";
        Map<String, Object> param = new HashMap<>();
        param.put("examId",examId);

        double score = examLibraryDao.findNotSubjectiveScore(param);
        return score;
    }

    //学生答题保存
    @Override
    public int examStudentSave(ExamStudentRecord examStudentRecord){

        examStudentRecord.setCreateDate(new Date());
        examStudentRecord.setUpdateDate(new Date());

        return examLibraryDao.examStudentSave(examStudentRecord);
    }

    @Override
    public int examStudentUpdate(ExamStudentRecord examStudentRecord){

        examStudentRecord.setUpdateDate(new Date());

        return examLibraryDao.examStudentUpdate(examStudentRecord);
    }

    @Override
    public int examStudentDelete(String studentId,String courseId,String examId,String testId){

        ExamStudentRecord examStudentRecord = new ExamStudentRecord();
        examStudentRecord.setStudentId(studentId);
        examStudentRecord.setCourseId(courseId);
        examStudentRecord.setExamId(examId);
        examStudentRecord.setTestId(testId);

        return examLibraryDao.examStudentDelete(examStudentRecord);
    }


    //学生成绩
    @Override
    public StudentScore findStudentScoreByMap(String studentId, String courseId, String semesterId){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("semesterId",semesterId);

        StudentScore studentScore = examLibraryDao.findStudentScoreByMap(param);

        return studentScore;
    }

    @Override
    public int studentScoreSave(StudentScore studentScore){

        studentScore.setCreateDate(new Date());
        studentScore.setUpdateDate(new Date());

        return examLibraryDao.studentScoreSave(studentScore);
    }

    @Override
    public int studentScoreUpdate(StudentScore studentScore){

        studentScore.setUpdateDate(new Date());

        return examLibraryDao.studentScoreUpdate(studentScore);
    }


}
